﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.IO;

public partial class kecheng_mp_kecheng_manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        string pattern = Request.QueryString.Get("title_id");
        //根据title_id来查询对应课程下的所有文件
        bindGrd(pattern);
    }

    protected void btnDel_Click(object sender, EventArgs e)
    {
        string[] ids = img_ids.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        int count = 0;
        using (Conn sqlCon = new Conn())
        {
            foreach (var item in ids)
            {
                string del = String.Format("update imgupload set convertStatus=6 where img_id={0}", item);
                try
                {
                    count += sqlCon.ExeSql(del);
                }
                catch (SqlException ex)
                {
                    string error = String.Format("showMessage('删除失败..." + " {0}' ", ex.Message);
                    ClientScript.RegisterClientScriptBlock(GetType(), "myScript", error, true);
                }
            }
        }
        if (!ClientScript.IsClientScriptBlockRegistered("myScript"))
        {
            if (count == 0)
            {
                ClientScript.RegisterClientScriptBlock(GetType(), "myScript", "showMessage('没有视频文件被删除');", true);
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(GetType(), "myScript", "showMessage('删除成功!');", true);
            }
        }

    }

    protected void bindGrd(string title_id)
    {
        using (Conn sqlCon = new Conn())
        {
            string sqlCommand = String.Format("select [img_id],[f_truename],[f_filename],[f_remark] from [ImgUpload] where [title_id]={0} and convertStatus<>6", title_id);
            DataSet ds = sqlCon.Conn_Send(sqlCommand);
            gdvKecheng.DataSource = ds.Tables[0];
            gdvKecheng.DataBind();
        }
    }

}
